package com.huidu.bitrade.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huidu.bitrade.result.page.MpPageQuery;
import com.huidu.bitrade.result.page.PageCondition;
import com.huidu.bitrade.result.PageResultByJPA;
import com.huidu.bitrade.entity.MemberLoan;
import com.huidu.bitrade.entity.transform.AuthMember;
import com.huidu.bitrade.service.MemberLoanService;
import com.huidu.bitrade.util.MessageResult;
import com.huidu.bitrade.vo.MemberLoanVO;
import com.huidu.bitrade.constant.SysConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

@Api(tags = "uc模块/用户变现")
@RestController("loan")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class MemberLoanController {

    private final MemberLoanService memberLoanService;

    @PostMapping("audit")
    @ApiOperation("申请变现")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "money",value = "金额",paramType = "form",required = true),
            @ApiImplicitParam(name = "number",value = "数量",paramType = "form",required = true),
            @ApiImplicitParam(name = "baseCoinSymbol",value = "币种",paramType = "form",required = true),
            @ApiImplicitParam(name = "payTYpe",value = "支付方式 1支付宝 2微信 3银行卡",paramType = "form",required = true),
    })
    public MessageResult audit(@ApiIgnore @SessionAttribute(SysConstant.SESSION_MEMBER) AuthMember member, @ApiIgnore MemberLoan memberLoan){
        memberLoan.setMemberId(member.getId());
        boolean apply = memberLoanService.apply(memberLoan);
        return apply ? MessageResult.success() : MessageResult.error("操作失败");
    }

    @GetMapping("list/{type}")
    @ApiOperation("列表")
    @ApiImplicitParam(name = "type",value = "1当前 2历史",paramType = "path",required = true)
    public MessageResult<PageResultByJPA<MemberLoanVO>> list(@ApiIgnore @SessionAttribute(SysConstant.SESSION_MEMBER) AuthMember member, @PathVariable("type") Integer type, MpPageQuery mpPageQuery){
        Page<MemberLoanVO> list = memberLoanService.list(PageCondition.page(mpPageQuery), member.getId(), type);
        return MessageResult.success("SUCCESS",PageCondition.buildData(list));
    }

//    @PostMapping("redemption/{id}")
//    @ApiOperation("申请赎回")
//    @ApiImplicitParam(name = "id",value = "编号",paramType = "path",required = true)
//    public MessageResult redemption(@PathVariable("id") Long id){
//        boolean apply = memberLoanService.redemption(id);
//        return apply ? MessageResult.success() : MessageResult.error("操作失败");
//    }




}
